<template>
  <div class="container" v-if="itemData && itemData.list.length > 0">
    <div class="contact-title">
      <span> {{ itemData.title }}</span>
    </div>

    <ul>
      <li
        :class="[item.id === activeId ? 'is-active' : '']"
        v-for="item in itemData.list"
        :key="item.id"
        @click="getDetail(item)"
      >
        <div class="avatar">
          <div v-if="itemData.group_key === 'new_friend'">
            <span
              class="iconfont icon-xindepengyou"
              style="font-size: 35px; color: #fa9d3b"
            ></span>
          </div>

          <div v-else-if="itemData.group_key === 'offical_account'">
            <span
              class="iconfont icon-gongzhonghao"
              style="font-size: 35px; color: #1485ee"
            ></span>
          </div>

          <div v-else-if="itemData.group_key === 'corporate_account'">
            <span
              class="iconfont icon-qiyehao"
              style="font-size: 35px; color: #4da7f3"
            ></span>
          </div>

          <div v-else>
            <AvatarBase :width="35" :show-detail="true"></AvatarBase>
          </div>
        </div>

        <div class="name">
          {{ item.name }}
        </div>
      </li>
    </ul>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
import AvatarBase from "../avatar/AvatarBase.vue";
import { ref } from "vue";

const router = useRouter();
const activeId = ref(0);

const props = defineProps({
  itemData: {
    type: Object,
    required: true,
  },
});

const getDetail = (item: any) => {
  // activeId.value = item.id;
  // 判断每一项类型，跳转不同页面
  if (props.itemData.type === 1) {
    router.push({ path: `/contact/newfriend/${item.id}` });
  } else if (props.itemData.type === 2) {
    router.push({ path: `/contact/friend/${item.id}` });
  } else if (props.itemData.type === 3) {
    router.push({ path: `/contact/offiaccount/${item.id}` });
  } else if (props.itemData.type === 5) {
    router.push({ path: `/contact/groupchat/${item.id}` });
  }
};
</script>

<style scoped lang="scss">
.container {
  min-height: 95px;
  border-bottom: 1px solid #d7d7d8;

  .contact-title {
    height: 35px;
    font-size: 12px;
    color: #a1a1a1;
    text-align: start;
    display: flex;
    align-items: center;
    justify-content: start;
    margin: 0;
    position: relative;

    span {
      position: absolute;
      bottom: 2px;
      left: 0;
      padding-left: 12px;
    }
  }

  ul {
    display: flex;
    flex-direction: column;
    align-items: start;
    width: 100%;

    li {
      display: flex;
      align-items: center;
      justify-content: start;
      height: 60px;
      width: 100%;
      padding: 0 12px 0 12px;

      &:hover {
        background-color: #d6d7d8;
      }

      .avatar {
        height: 35px;
        width: 35px;
        margin-right: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      .name {
        flex: 1;
        line-height: 60px;
        font-size: 15px;
        color: #000000;
        white-space: nowrap; // 强制单行显示
        overflow: hidden; // 超出部分隐藏
        text-overflow: ellipsis; // 显示省略号
      }
    }

    li.is-active {
      background-color: #c4c4c4;
    }
  }
}
</style>
